import { MockMethod } from 'vite-plugin-mock';
import { mock, Random } from 'mockjs';
import NETWORK_DELAY from '..';
import {
  EducationMockList,
  JobIntroAceMockList,
  JobIntroDescriptionMockList,
  JobNameMockList,
  JobStatusMockList,
  locationMockList,
  YearRequereMockList,
} from '../../common/MockNameList';
import { Candidate } from '../../../src/types/Candidate';

const generateCandidatesMockData = () => {
  const candidateList = mock({
    'data|10': [
      {
        'id|+1': 900100,
        name: '@cname',
        resume_name: '@cname()的简历.pdf',
        resume_url: 'www.baidu.com',
        interviews: '@interviews',
      },
    ],
  });
  candidateList.data.forEach((item: Candidate) => {
    const target = item;
    if (item.interviews.length === 0) {
      target.stage = '未开始面试';
    } else if (item.interviews.length === 3) {
      target.stage = Random.pick(['面试失败', '面试通过']);
    } else {
      const stageList = ['第一轮面试', '第二轮面试', '第三轮面试'];
      target.stage = stageList[item.interviews.length - 1];
    }
  });
  return mock({
    data_list: candidateList.data,
  });
};

const generateJobListMockData = () => {
  const jobList = mock({
    'data|10': [
      {
        // 工作ID
        'id|+1': 300100,
        // 职位标题
        'title|1': JobNameMockList,

        // 职位发布时间
        publish_time: '@date("yyyy/MM/dd HH:mm:ss")',
        // 职位访问次数
        visit_num: '@natural(1, 200)',
        // 收到的简历
        resume_num: '@natural(1, 20)',
        // 职位状态
        'status|1': JobStatusMockList,
        // 职位预览URL
        job_url: 'www.baidu.com',
        // 目标人数
        target: '@natural(3, 10)',
        // 已录取人数
        current: '@natural(0, 3)',
        // 发布者姓名
        publisher_name: '@cname',
      },
    ],
  });
  return mock({
    data_list: jobList.data,
    cur: '@natural(1,10)',
    total: 100,
  });
};

const generateJobDetailMockData = () => {
  return mock({
    // 工作ID
    'id|+1': 300100,
    // 职位标题
    'title|1': JobNameMockList,
    // 职位状态
    'status|1': JobStatusMockList,
    // 目标人数
    target: '@natural(3, 10)',
    // 发布人ID，这里暂时使用名称代替
    publisher_id: '@cname',
    // 学历要求
    'require_education|1': EducationMockList,
    // 经验要求
    'require_experience|1': YearRequereMockList,
    // 薪水最低
    salary_low: '@natural(5, 14)',
    // 薪水最高
    salary_high: '@natural(15, 20)',
    // 多少薪水
    salary_times: '@natural(12, 15)',
    // 地址
    'location|1': locationMockList,
    // 职位诱惑
    'intro|1': JobIntroAceMockList,
    // 职位介绍
    'detail|1': JobIntroDescriptionMockList,
  });
};
export default [
  {
    url: '/api/joblist',
    method: 'get',
    timeout: NETWORK_DELAY,
    statusCode: 200,
    response: () => {
      return generateJobListMockData();
    },
  },
  {
    url: '/api/job',
    method: 'put',
    timeout: NETWORK_DELAY,
    statusCode: 201,
    response: () => {
      return null;
    },
  },
  {
    url: '/api/job',
    method: 'get',
    timeout: NETWORK_DELAY,
    statusCode: 200,
    response: () => {
      return generateJobDetailMockData();
    },
  },
  {
    url: '/api/job',
    method: 'post',
    statusCode: 201,
    timeout: NETWORK_DELAY,
    response: () => {
      return null;
    },
  },
  {
    url: '/api/candidatelist',
    method: 'get',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => {
      return generateCandidatesMockData();
    },
  },
  {
    url: '/api/candidate',
    method: 'put',
    statusCode: 200,
    timeout: NETWORK_DELAY,
    response: () => {
      return null;
    },
  },
] as MockMethod[];
